using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Qreed.Xna.Font
{
    public class VectorFont
    {
        #region Properties

        private Dictionary<char, VectorFontCharacterBase> _characterMap = new Dictionary<char, VectorFontCharacterBase>();
        /// <summary>
        /// Gets the character map.
        /// </summary>
        /// <value>The character map.</value>
        internal Dictionary<char, VectorFontCharacterBase> CharacterMap
        {
            get { return _characterMap; }
        }

        /// <summary>
        /// Gets the <see cref="Qreed.Xna.Font.VectorFontCharacter"/> for the specified character.
        /// </summary>
        /// <value></value>
        public VectorFontCharacterBase this[char character]
        {
            get
            {
                if (CharacterMap.ContainsKey(character))
                    return CharacterMap[character];

                return default(VectorFontCharacterBase);
            }
        }
			
        private float _lineHeight;
        /// <summary>
        /// Gets the height of the line.
        /// </summary>
        /// <value>The height of the line.</value>
        public float LineHeight
        {
            get { return this._lineHeight; }
            internal set { this._lineHeight = value; }
        }

        private string _fontName;
        /// <summary>
        /// Gets the name of the font.
        /// </summary>
        /// <value>The name of the font.</value>
        public string FontName
        {
            get { return this._fontName; }
            internal set { this._fontName = value; }
        }

        private Dictionary<VectorFontCharacterKerningPair, Vector2> _kerningTable = new Dictionary<VectorFontCharacterKerningPair, Vector2>();
        /// <summary>
        /// Gets or sets the kerning table.
        /// </summary>
        /// <value>The kerning table.</value>
        internal Dictionary<VectorFontCharacterKerningPair, Vector2> KerningTable
        {
            get { return this._kerningTable; }
            set { _kerningTable = value; }
        }

        #endregion

        #region Functions

        /// <summary>
        /// Gets the kerning.
        /// </summary>
        /// <param name="leftCharacter">The left character.</param>
        /// <param name="rightCharacter">The right character.</param>
        /// <returns></returns>
        public Vector2 GetKerning(char leftCharacter, char rightCharacter)
        {
            VectorFontCharacterKerningPair pair = new VectorFontCharacterKerningPair(leftCharacter, rightCharacter);
            return GetKerning(pair);
        }

        /// <summary>
        /// Gets the kerning.
        /// </summary>
        /// <param name="pair">The kerning pair.</param>
        /// <returns></returns>
        private Vector2 GetKerning(VectorFontCharacterKerningPair pair)
        {
            if (KerningTable.ContainsKey(pair))
                return KerningTable[pair];

            return Vector2.Zero;
        }

        #endregion
    }
}
